package com.express.e.root.service.impl;

import com.express.e.root.bean.User;
import com.express.e.root.dao.UserDao;
import com.express.e.root.dao.impl.UserDaoImpl;
import com.express.e.root.service.UserService;

import java.util.List;

public class UserServiceImpl implements UserService {
    private UserDao userDao = new UserDaoImpl();

    @Override
    public User addUser(User user) {
        Boolean addFlag = userDao.addUser(user);
        if (addFlag) {
            return userDao.queryByName(user.getUserName());
        }
        return null;
    }

    @Override
    public Boolean delUser(Integer userId) {
        return userDao.deleteUser(userId);
    }

    @Override
    public User updateUser(User user) {
        Boolean updateFlag = userDao.updateUser(user);
        if (updateFlag) {
            return userDao.queryByName(user.getUserName());
        }
        return null;
    }

    @Override
    public List userList() {
        return userDao.listUser();
    }

    @Override
    public User queryById(Integer userId) {
        return userDao.queryById(userId);
    }

    @Override
    public User queryByPhone(String phone) {
        return userDao.queryByPhone(phone);
    }

    @Override
    public User queryByCardId(String cardId) {
        return userDao.queryByCardId(cardId);
    }

    @Override
    public User queryByUserName(String name) {
        return userDao.queryByName(name);
    }

    @Override
    public Boolean userLogin(User user) {
        User queryByName = userDao.queryByName(user.getUserName());
        if (queryByName != null && queryByName.getUserPwd()!=null) {
            if (queryByName.getUserPwd().equals(user.getUserPwd())) {
                return true;
            }
        }
        return false;
    }


}
